# leetcode submit region begin(Prohibit modification and deletion)
class Solution:
    def countAndSay(self, n: int) -> str:
        if n == 1:
            return "1"
        if n == 2:
            return "11"
        re = ["" for i in range(n)]
        re[0] = "1"
        re[1] = "11"
        for i in range(2, n):
            left = 0
            right = 1
            count = 1
            while left <= right < len(re[i - 1]):
                if re[i - 1][left] == re[i - 1][right]:
                    count += 1
                    right += 1
                else:
                    re[i] = re[i] + str(count) + re[i - 1][left]
                    left, right = right, right + 1
                    count = 1
            re[i] = re[i] + str(count) + re[i - 1][-1]

        return re[-1]


# leetcode submit region end(Prohibit modification and deletion)

if __name__ == '__main__':
    a = Solution()
    n = 6
    print(a.countAndSay(n))
